#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include "rngs.h"

#define DEBUG 0
#define NOISY_TEST 1

/* This file is a random unit test for the 'council room' card */
int checkCR(int currPlayer, struct gameState *state, int handPos) {
	struct gameState pre;
	
	memcpy(&pre, state, sizeof(struct gameState));

	int i, r;
	int startingHand, startingBuys, players;

	startingHand = pre.handCount[currPlayer];
	startingBuys = pre.numBuys;	
	players = pre.numPlayers;
	
	r = Council_Room(currPlayer, state, handPos);

	if ((state->handCount[currPlayer] - startingHand) < 3){
		printf("Not enough cards were drawn\n");
	}
	else if ((state->handCount[currPlayer] - startingHand) > 3){
		printf("Too many cards were drawn\n");
	}
	
	if ((state->numBuys - startingBuys) < 1) {
		printf("numBuys was not incremented\n");
	}
	else if ((state->numBuys - startingBuys) > 1){
		printf("numBuys was incremented too much\n");
	}

	for (i = 0; i < players; i++) {
		if (i != currPlayer){
			if ((state->deckCount[i] - pre.deckCount[i]) >= 1) {
				printf("Player %d did not draw a card\n", i);
			}
		}
	}

	return 0;
}

int main() {
	int i, n, p, r, deckCount, handCount;
	int handPos = Random() * 5;
	int k[10] = {adventurer, council_room, feast, gardens, mine,
			remodel, smithy, village, baron, great_hall};

	struct gameState G;

	printf("Testing 'council_room' card\n");
	printf("Random tests\n");

	SelectStream(2);
	PutSeed(3);

	for (p = 0; p < 4; p++) {
		for (deckCount = 0; deckCount < 5; deckCount++) {
			for (handCount = 0; handCount < 5; handCount++) {
				for (handPos = 0; handPos < 5; handPos++) {
					memset(&G, 23, sizeof(struct gameState));
					r = initializeGame(4, k, 1, &G);
					G.deckCount[p] = deckCount;
					memset(G.deck[p], 0, sizeof(int) * deckCount);
					G.handCount[p] = handCount;
					memset(G.hand[p], 0, sizeof(int) * handCount);
					checkCR(p, &G, handPos);
				}
			}
		}
	}

	return 0;
} 
